package com.lottery.ruok.lottrey.ui;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.View;

public abstract class BaseCustomeView extends View {
    private MyThread myThread = null;
    public boolean stop = false;
    private class MyThread extends Thread {
        @Override
        public void run() {
            while(!stop){
                logicDo();
                postInvalidate(); //通知更新界面，会重新调用onDraw()函数
                try{
                    sleep(50);
                }catch(Exception e){
                    e.printStackTrace();
                }
            }
        }
    }
    public abstract void logicDo(); //逻辑处理方法
    public abstract void drawSub(Canvas canvas); //绘画内容代码
    public abstract void initView();
    @Override
    protected void onDraw(Canvas canvas) {
        if(myThread == null){  //第一次调用onDraw()方法的时候会创建一个线程，用来实现小球的碰撞弹回
            initView();//初始化View方法
            myThread = new MyThread();
            myThread.start();    //启动线程
        }else{
            drawSub(canvas);    //如果线程以创建，则调用绘制方法
        }
    }
    public BaseCustomeView(Context context) {
        super(context);
    }
    public BaseCustomeView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
}
